package com.punai.config.controller;

import com.punai.common.core.controller.BaseController;
import com.punai.common.core.domain.AjaxResult;
import com.punai.common.core.page.TableDataInfo;
import com.punai.config.domain.vo.ConfigMaterialCategoryVo;
import com.punai.config.domain.vo.ConfigMaterialInfoVo;
import com.punai.config.service.ConfigMaterialPLCService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/config/materialPLCManage")
public class ConfigMaterialPLCController extends BaseController {

    @Autowired
    private ConfigMaterialPLCService materialPLCService;
    @PreAuthorize("@ss.hasPermi('config:materialPLCManage:addressList')")
    @GetMapping("/getAllAddress")
    public AjaxResult getAllAddress(ConfigMaterialCategoryVo vo) {
        return AjaxResult.success(materialPLCService.getAllAddress(vo.getType()));
    }

    @PreAuthorize("@ss.hasPermi('config:materialPLCManage:categoryInfo')")
    @GetMapping("/getCategoryInfo")
    public AjaxResult getCategoryInfo(ConfigMaterialCategoryVo vo) {
        return AjaxResult.success(materialPLCService.getCategoryInfo(vo.getId()));
    }

    @PreAuthorize("@ss.hasPermi('config:materialPLCManage:categoryList')")
    @GetMapping("/getTreeCategory")
    public AjaxResult getTreeCategory(ConfigMaterialCategoryVo vo) {
        return AjaxResult.success(materialPLCService.getTreeCategory(vo.getPid(), vo.getType()));
    }
    @PreAuthorize("@ss.hasPermi('config:materialPLCManage:saveCategory')")
    @GetMapping("/saveCategory")
    public AjaxResult saveCategory(ConfigMaterialCategoryVo vo) {
        return AjaxResult.success(materialPLCService.saveCategory(vo));
    }

    @PreAuthorize("@ss.hasPermi('config:materialPLCManage:removeCategory')")
    @GetMapping("/removeCategory")
    public AjaxResult removeCategory(ConfigMaterialCategoryVo vo) {
        return AjaxResult.success(materialPLCService.removeCategory(vo.getId()));
    }
    @PreAuthorize("@ss.hasPermi('config:materialPLCManage:materialList')")
    @GetMapping("/getMaterialList")
    public TableDataInfo materialList(ConfigMaterialInfoVo vo) {
        return getDataTable(materialPLCService.getAllInfo(vo));
    }

    @PreAuthorize("@ss.hasPermi('config:materialPLCManage:materialInfo')")
    @GetMapping("/getMaterialInfo")
    public AjaxResult getMaterialInfo(ConfigMaterialInfoVo vo) {
        return AjaxResult.success(materialPLCService.getMaterialInfo(vo.getId()));
    }
    @PreAuthorize("@ss.hasPermi('config:materialPLCManage:saveMaterialInfo')")
    @GetMapping("/saveMaterialInfo")
    public AjaxResult saveMaterialInfo(ConfigMaterialInfoVo vo) {
        return AjaxResult.success(materialPLCService.saveMaterialInfo(vo));
    }

    @PreAuthorize("@ss.hasPermi('config:materialPLCManage:removeMaterialInfo')")
    @GetMapping("/removeMaterialInfo")
    public AjaxResult removeMaterialInfo(ConfigMaterialInfoVo vo) {
        return AjaxResult.success(materialPLCService.removeMaterialInfo(vo));
    }
}
